package com.dunqi.gpm.shunqing.home.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.dunqi.gpm.shunqing.R;

/**
 * Created by 空 on 2017/11/17 0017.
 */
public class SpinnerAdapter extends ArrayAdapter<String> {

    private final String[] strings;
    private LayoutInflater inflater;


    public SpinnerAdapter(@NonNull Context context, @NonNull String[] strings) {
        super(context, R.layout.spinner_checked_text, strings);
        this.strings = strings;
        inflater = LayoutInflater.from(context);

    }

    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_home_spinner_year, null);

        TextView label = view
                .findViewById(R.id.text_tv);
        label.setText(strings[position]);

        View top_line = view.findViewById(R.id.top_line);
        View bottom_line = view.findViewById(R.id.bottom_line);

        int length = strings.length;
        if (position == 0) {
            top_line.setVisibility(View.VISIBLE);
            bottom_line.setVisibility(View.GONE);
        } else if (position == length - 1) {
            bottom_line.setVisibility(View.VISIBLE);
            top_line.setVisibility(View.GONE);
        } else {
            bottom_line.setVisibility(View.GONE);
            top_line.setVisibility(View.GONE);
        }

        return view;
    }
}
